<!--
 * FilePath     : \src\components\selector\avoidHolidaySelector.vue
 * Author       : 来江禹
 * Date         : 2025-02-13 14:55
 * LastEditors  : 来江禹
 * LastEditTime : 2025-02-15 11:51
 * Description  : 跳过节假日方式组件
 * CodeIterationRecord:
 -->
<template>
  <el-select v-model="avoidHolidayValue" :placeholder="placeholder" @change="emitSelectOption" :clearable="clearable">
    <el-option v-for="item in options" :key="item.value" :label="item.label" :value="item.value"></el-option>
  </el-select>
</template>

<script setup lang="ts">
const { commonDictionaryStore } = useStore();
const { avoidHolidayOptions } = defineProps<{
  avoidHolidayOptions?: SelectOptionsView[];
  clearable: {
    type: Boolean;
    default: false;
  };
  placeholder: {
    type: String;
    default: "请选择";
  };
}>();
const avoidHolidayValue = defineModel({
  type: String,
  default: undefined
});
(avoidHolidayOptions ?? []).length == 0 &&
  commonDictionaryStore.fetchDataIfNeeded("avoidHolidaySettingList", settingDictionaryService.getAvoidHolidaySelectList);
/**
 * @description:组装下拉框选项
 * @param computed
 * @return
 */
const options = computed(() => {
  return (avoidHolidayOptions ?? []).length > 0 ? avoidHolidayOptions ?? [] : commonDictionaryStore?.avoidHolidaySettingList ?? [];
});
const emit = defineEmits(["select"]);
/**
 * @description: 选中内容事件发射
 */
const emitSelectOption = () => {
  emit(
    "select",
    options.value.find((item: SelectOptionsView) => item.value == avoidHolidayValue.value)
  );
};
</script>
